<?php
/**
 * Base_App
 *
 * LICENSE
 *
 * This source file is subject to the new CC-GNU LGPL
 * It is available through the world-wide-web at this URL:
 * http://creativecommons.org/licenses/LGPL/2.1/
 *
 * @category   Base_App
 * @copyright  Copyright (c) 2009 Alexander fanatique* Thomas (me@alexander-thomas.net)
 * @license    http://creativecommons.org/licenses/LGPL/2.1/
 */

/**
 * Static wrapper for all table classes
 * @todo must be cached!
 */ 
class Service_Tables 
{
	private static $_instance;
	private $_log;
	private $_tables = array();
	
	function __construct(){
		$this->_log = Zend_Registry::get('log');
		$this->_log->info('Tables __construct()');
	}

	public static function getInstance(){
		if(self::$_instance === null){
			self::$_instance = new Service_Tables();
		}
		return self::$_instance;
	}

	public function __get($name){
		$className = 'Model_' . ucfirst($name);
		if(!isset($this->_tables[$name]) && class_exists($className) === true){
			$this->_tables[$name] = new $className(array('db' => 'db'));
		}else if(class_exists($className) !== true){
			throw new Exception("$className does not exist.");
		}
		return $this->_tables[$name];
	}
}
?>
